<?php
/**
 * Date: 2024.8
 * Author: kahn
 * 微信公众号内支付
 */
use config\Response;
use service\vip\payment\WxpayService;

class PublicController extends Controller
{

    /**
     * 如果前端网址被设置成微信授权域名, 则前端可直接获取到code, 从而调用该接口获取openId
     * 微信公众号支付前, 通过code获取openId
     * @return void
     */
    public function openIdAction(): void
    {
        $code = $this->_getParam('code','string');

        $openId = WxpayService::getPublicOpenId($code);

        if(!$openId){
            $this->_response(Response::PUBLIC_OPENID_FAIL);
        }

        $this->_response(Response::SUCCESS, ['openId'=>$openId]);
    }
}

